// 存储用户三级菜单的信息
import { defineStore } from "pinia";
// 发送请求的接口
import { reqC1, reqC2, reqC3 } from "@/api/product/attr/index";
// 导入定义的ts类型的接口
import type { CatgoryArr } from "@/api/product/attr/type/index";
// 导入在接口定义的
import type { CategoryState } from "./interface/index";
// 定义仓库
const useCategoryStore = defineStore("Category", {
  state: (): CategoryState => {
    return {
      c1Arr: [],
      c1Id: "",
      c2Arr: [],
      c2Id: "",
      c3Arr: [],
      c3Id: "",
    };
  },
  actions: {
    // 组件挂载完成 发送请求
    // 获取一级分类的信息
    async getC1() {
      // 发送一级分类的信息
      let result: CatgoryArr = await reqC1();
      // 存储一级分类的信息
      this.c1Arr = result;
    },
    // 获取二级的菜单
    async getC2() {
      let result: CatgoryArr = await reqC2(this.c1Id);
      this.c2Arr = result;
    },
    // 获取三级的菜单
    async getC3() {
      let result: CatgoryArr = await reqC3(this.c2Id);
      this.c3Arr = result;
    },
  },
});

export default useCategoryStore;
